<div class="wrap">
	<div class="header">
		<a href="javascript:void(0)" id="addBtn">添加员工</a>
	</div>
	<table class="table">
		<thead>
			<tr>
				<th>工号</th>
				<th>姓名</th>
				<th>所属部门</th>
				<th>联系电话</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody id="orderCont">
		</tbody>
	</table>
</div>
<!--遮罩层-->
<div class="layout">
	<div class="alert">
		<h3>添加员工</h3>
		<p>
			<label>姓名</label>
			<input type="text" id="name">
		</p>
		<p>
			<label>性别</label>
			<select id="sex">
				<option>男</option>
				<option>女</option>
			</select>
		</p>
		<p>
			<label>所属部门</label>
			<select id="location">	</select>
		</p>
		<p>
			<label>联系电话</label>
			<input type="text" id="tel" maxlength="11">
		</p>
		<p>
			<a href="javascript:void(0)" id="submitBtn">提交</a>
			<a href="javascript:void(0)" class="curr" id="cancelBtn">取消</a>
		</p>
	</div>
</div>
<script>
	//展示员工
	$.ajax({
		type:"post",
		url:"http://39.108.164.20/device/SysUser/UserInfoList",
		dataType:"json",
		success:function(res){
			$("#orderCont").empty();
			console.log(res);
			var data = res.result.data;
			var html;
			for(let i=0;i<data.length;i++){
				html += '<tr data-id="'+data[i].uuid+'"><td>'+data[i].uuid+'</td><td>'+data[i].pet_name+'</td><td>'+data[i].clerk_name+'</td><td>'+data[i].phone_number+'</td><td><a href="javascript:void(0)" onclick="delFun()">删除</a></td></tr>';
			}
			$("#orderCont").append(html);
		}
	});
	//取消弹窗
	$("#cancelBtn").on("click",function(){
		$(".layout").hide();
		$(".alert").hide();
	})
	//添加公司信息
	$("#addBtn").on("click",function(){
		$(".layout").show();
		$(".alert").show();
	})
	//所属部门
	$.ajax({
		type:"post",
		url:"http://39.108.164.20/device/SysUser/ClerkList",
		dataType:"json",
		success:function(res){
			var data = res.result.data;
			var html;
			for(let i=0;i<data.length;i++){
				html += '<option data-id="'+data[i].clerk_id+'">'+data[i].clerk_name+'</option>'
			}
			$("#location").append(html);
		}
	});
	//确认
	$("#submitBtn").on("click",function(){
		var name = $("#name").val(),
			clerk_id = $("#location option:selected").attr("data-id"),
			tel = $("#tel").val(),
			sex = $("#sex").val(),
			address = $("#location").val();
		$.ajax({
			type:"post",
			url:"http://39.108.164.20/device/SysUser/InsUserInfo",
			dataType:"json",
			data:{
				name:name,
				sex:sex,
				clerk_id:clerk_id,
				phone_number:tel,
				address:address
			},
			success:function(res){
				$(".layout").hide();
				$(".alert").hide();
				if(res.result.success==0){
					alert("增加成功！");
					//展示员工
					$.ajax({
						type:"post",
						url:"http://39.108.164.20/device/SysUser/UserInfoList",
						dataType:"json",
						success:function(res){
							$("#orderCont").empty();
							var data = res.result.data;
							var html;
							for(let i=0;i<data.length;i++){
								html += '<tr data-id="'+data[i].uuid+'"><td>'+data[i].uuid+'</td><td>'+data[i].pet_name+'</td><td>'+data[i].clerk_name+'</td><td>'+data[i].phone_number+'</td><td><a href="javascript:void(0)" onclick="delFun($(this))">删除</a></td></tr>';
							}
							$("#orderCont").append(html);
						}
					});
				}
			}
		});
	})
	//删除
	function delFun(e){
		var uid = e.parents("tr").attr("data-id");
		if(confirm("您确定要删除吗？")){
			$.ajax({
				type:"post",
				url:"http://39.108.164.20/device/SysUser/DelOrder",
				dataType:"json",
				data:{
					uid:uid,
					type:"delUser"
				},
				success:function(res){
					if(res.result.success == 0){
						alert("删除成功！");
						//展示员工
						$.ajax({
							type:"post",
							url:"http://39.108.164.20/device/SysUser/UserInfoList",
							dataType:"json",
							success:function(res){
								$("#orderCont").empty();
								console.log(res);
								var data = res.result.data;
								var html;
								for(let i=0;i<data.length;i++){
									html += '<tr data-id="'+data[i].uuid+'"><td>'+data[i].uuid+'</td><td>'+data[i].pet_name+'</td><td>'+data[i].clerk_name+'</td><td>'+data[i].phone_number+'</td><td><a href="javascript:void(0)" onclick="delFun()">删除</a></td></tr>';
								}
								$("#orderCont").append(html);
							}
						});
					}
				}
			});
		}
	}
</script>
